package com.ybwh.springboot1.websocket.client;

import java.net.URI;

import javax.websocket.ContainerProvider;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;

import com.alibaba.fastjson.JSON;
import com.ybwh.springboot1.websocket.client.ReqMsg.Entry;
import com.ybwh.springboot1.websocket.client.ReqMsg.IMMsgData;

public class ClientStart {
    public static void main(String[] args){
        try {
            WebSocketContainer container = ContainerProvider.getWebSocketContainer();
            MyClient client = new MyClient();
            Session session =container.connectToServer(client, new URI("ws://172.16.116.71/imcp/shangxinweb/ws"));
//            container.setDefaultMaxSessionIdleTimeout(5000L);
//            session.addMessageHandler(handler);
            System.out.println("sessionId"+session.getId());
          
            ReqMsg reqMsg = new ReqMsg();
        	ReqMsg.Entry entry = new Entry();
        	entry.setCid(6001L);
        	entry.setImid(233L);
        	entry.setUniqueKey("eeeeee");
        	entry.setClientType(3);
        	
        	ReqMsg.IMMsgData data = new IMMsgData();
        	data.setSessionId(233L);
        	data.setFromUserName("test");
        	data.setSessionType(1);
        	data.setMsgType(1);
        	data.setMsgContent("this is a push  test!!");
        	
        	reqMsg.setEntry(entry);
        	reqMsg.setIMMsgData(data);
        	
        	
        	
        	
        	String content=JSON.toJSONString(reqMsg);
        	System.out.println(content);
            
        	System.out.println("send:"+Thread.currentThread().getId());
//            client.send(content);
//        	session.getAsyncRemote().sendText(content);
        	
        	session.getBasicRemote().sendText(content);
            
            
            System.in.read();
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}